<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 300px;
            height: 300px;
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <div id="div1"></div>
    <button id="btn">变色</button>
    <button id="btn1">停止</button>
    <script>
        onload=function(){
            var mytime
            btn.onclick=function(){
            mytime=setInterval(function(){
            var str="#"
            var arr=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]
            for(var i=0; i<6;i++){
                var num=parseInt(Math.random()*16) 
                str+=arr[num]
            }
            div1.style.backgroundColor=str
        },10)
        }
        btn1.onclick=function(){
            clearInterval(mytime)
        }
        }
       
     
    </script>
</body>
</html>